#include <iostream>
using namespace std;

const int MAX_ROW = 10;
const int MAX_CLOUMN = 100;

int main(int argc, char* argv[])
{
	struct Node
	{
		int weight;
		int prev;
	};

	int M[ MAX_ROW ][ MAX_CLOUMN ] = {0};
	Node F[ MAX_ROW ][ MAX_CLOUMN ] = {0};

	while( 1 )
	{
		int row = 0;
		int cloumn = 0;
		if( !( cin >> row >> cloumn ) )
		{
			return 0;
		}

		for( int i = 0; i < row; i++ )
		{
			for( int j = cloumn - 1; j >= 0; j-- )
			{
				cin >> M[i][j];
			}
		}

		for( int r = 0; r < row; r++ )
		{
			Node& node = F[r][0];
			node.weight = M[r][0];
			node.prev = -1;
		}

		for( int c = 1; c < cloumn; c++ )
		{
			for( int r = 0; r < row; r++ )
			{
				int min = INT_MAX;
				int prev = INT_MAX;
				for( int k = -1; k <= 1; k++ )
				{
					int r0 = r + k;
					if( r0 < 0 ) r0 = row - 1;
					else if( r0 == row ) r0 = 0;
					Node& node = F[r0][c-1];
					if( min > node.weight )
					{
						min = node.weight;
						prev = r0;
					}
					else if( min == node.weight )
					{
						if( prev > r0 ) prev = r0;
					}
				}
				Node& node = F[r][c];
				node.weight = min + M[r][c];
				node.prev = prev;
			}
		}

		int min = INT_MAX;
		int prev = -1;
		for( int i = 0; i < row; i++ )
		{
			if( min > F[i][cloumn-1].weight )
			{
				min = F[i][cloumn-1].weight;
				prev = i;
			}
		}

		for( int i = cloumn - 1; i >= 0; i-- )
		{
			cout << prev + 1;
			if( i != 0 ) cout << " ";
			prev = F[prev][i].prev;
		}
		cout << endl << min << endl;
	}
}
